<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <ul id="ul">
    <li id="id1" class="class1">item1</li>
    <li id="id2" class="class2">item2</li>
    <li id="id3" class="class3">item3</li>
    <li id="id4" class="class4">item4</li>
  </ul>
  <script>
    document.getElementById('ul').addEventListener('click', e => {
      if (e.target.nodeName === 'LI') {
        console.log('点击的节点名字：', e.target.nodeName);
        console.log('点击的节点id：', e.target.id);
        console.log('点击的节点class名：', e.target.className);
      }
    })
    
    // document.getElementById('ul').addEventListener('click', function (e) {
    //   // 兼容性处理
    //   let event = e || window.event
    //   let target = event.target || event.srcElement

    //   // 判断是否匹配目标元素
    //   if (target.nodeName === 'LI') {
    //     console.log('click->', target.innerHTML);
    //   }
    // })
  </script>
</body>

</html>